package com.example.ch05_springboot_web.service;


import com.example.ch05_springboot_web.entity.User;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class UserService implements IUserService {

    private static Map<Integer, User> map = new HashMap<>();

    static {
        map.put(1, new User(1, "张三", "北京"));
        map.put(2, new User(2, "李四", "南京"));
        map.put(3, new User(3, "王五", "上海"));
        map.put(4, new User(4, "赵四", "东北"));
        map.put(5, new User(5, "奥巴马", "美国"));
    }

    @Override
    public List<User> getAllUser() {
        return null;
    }

    @Override
    public void update(User user) {

    }

    @Override
    public User getUserById(Integer id) {
        return map.get(id);
    }

    @Override
    public User addUser(User user) {
        map.put(6, user);
        return map.get(6);
    }

    @Override
    public void deleteUser(Integer id) {
        map.remove(id);
        System.out.println("user‘s size = " + map.size());
    }
}
